//
//  BGOPersistenceManager.h
//  Bango iOS API
//
//  Created by William Shakour on September 2, 2011.
//  Copyrights © 2011 Bango - http://www.bango.net/ - All rights reserved.
//

@class FMDatabase;
@class FMStatement;
@class BGOProfile;

#define DEFAULT_POST_CHUNK_SIZE 10
#define MIN_POST_CHUNK_SIZE 1
#define MAX_POST_CHUNK_SIZE 500

@interface BGOPersistenceManager : NSObject {
 @private
  FMDatabase *_database;
  NSString *_insertProfileStatement, *_insertEventStatement,
  *_insertEventParameterStatement;
  BOOL _persistDatabaseConnection, _isOpen, _openLogProfile,
  _openUpdateProfileLocation, _openLogEvent, _openProfilesForPost,
  _openEventsForPost, _openEventsPosted, _openDeleteEventsPosted;
  int _profileId, _postChunkSize;
}

@property (nonatomic, readonly) NSString *profileTableName;
@property (nonatomic, readonly) NSString *eventTableName;
@property (nonatomic, readonly) NSString *eventParameterTableName;
@property (nonatomic, readonly) NSString *databaseName;
@property (nonatomic, setter = setDebugLog:, getter = isDebugLog) BOOL debugLog;
@property (nonatomic, assign) int postChunkSize;

+(BGOPersistenceManager *)sharedPersistenceManager;
-(void)compactDatabase;
-(void)createTables;
-(void)dropTables;
-(void)openDatabase;
-(void)openDatabaseWithForce:(BOOL)forceOpen;
-(void)closeDatabase;
-(void)logProfileWithSdkType:(int)sdkType
                  sdkVersion:(NSString *)sdkVersion
               applicationId:(NSString *)applicationId
             applicationType:(NSString *)applicationType
          applicationChannel:(NSString *)applicationChannel
          applicationVersion:(NSString *)applicationVersion
                      userId:(NSString *)userId
          sessionRestartTime:(int)sessionRestartTime
                     created:(NSDate *)created
              connectionType:(NSString *)connectionType
                   isRoaming:(BOOL)isRoaming
              locationSource:(NSString *)locationSource
            locationAltitude:(double)locationAltitude
            locationLatitude:(double)locationLatitude
           locationLongitude:(double)locationLongitude
            locationAccuracy:(double)locationAccuracy
                 netOperator:(NSString *)netOperator
                operatorName:(NSString *)operatorName
          operatorCountryIso:(NSString *)operatorCountryIso
                 simOperator:(NSString *)simOperator
                       brand:(NSString *)brand
                      device:(NSString *)device
                   ipAddress:(NSString *)ipAddress
                       model:(NSString *)model
                     product:(NSString *)product
                     version:(NSString *)version
                     buildId:(NSString *)buildId
      operatorConnectionType:(NSString *)operatorConnectionType;
-(void)updateProfileLocationWithLocationLatitude:(double)locationLatitude
                               locationLongitude:(double)locationLongitude 
                                locationAltitude:(double)locationAltitude
                                locationAccuracy:(double)locationAccuracy;
-(void)logEventWithConnectionType:(NSString *)connectionType
          operatorConnectionType:(NSString *)operatorConnectionType
                      errorLevel:(int)errorLevel
                       eventName:(NSString *)eventName
                     eventDetail:(NSString *)eventDetail
                      eventValue:(NSString *)eventValue
                         errorId:(NSString *)errorId
                       eventTime:(NSDate *)eventTime
                 eventParameters:(NSDictionary *)eventParameters;
-(void)logEventParameterWithEventId:(int)eventId
                    eventParameters:(NSDictionary *)eventParameters;
-(BOOL)updateEventsPosted:(int)profileId;
-(BOOL)updateEventsPostInProgress:(BGOProfile *)profile;
-(BOOL)deleteEventsPosted:(int)profileId;
-(NSArray *)getProfilesForPost:(BOOL)notCurrentProfile;
-(NSArray *)getProfilesForPost:(BOOL)notCurrentProfile chunked:(BOOL)inChuncks;
-(BOOL)isCurrentProfile:(int)profileId;

@end
